#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
//waitpid需要的头文件
#include <sys/types.h>
#include <sys/wait.h>
char* myargv[]={
  "ls",
  "-l",
  "-a",
  NULL 
};

/*int main()
{
    printf("before:I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
    //这类方法的标准写法
    //execl("/usr/bin/ls","ls","-a","-l",NULL);
    //execlp("ls","ls","-a","-l",NULL);    
    //execl("/usr/bin/top","top",NULL);
    //execv("/usr/bin/ls",myargv);
    execvp("ls",myargv);

    //printf("before:I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
    printf("after:I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
    
    return 0;
}*/
int main()
{
  extern char **environ;
  //putenv("PRIVATE_ENV=666666");
  pid_t id = fork();
  if(id == 0)
  {
    printf("I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
    char* const myargv[]=
    {
      "otherExe",
      "-a",
      "-b",
      "-c",
      NULL 
    };
    char *const myenv[] = {
      "MYVAL=1111",
      "MYPATH=/usr/bin/XXX",
      NULL 
  };
    execle("./otherExe","otherExe","-a","-w","-v",NULL,myenv);
    printf("after: I am a process, pid: %d, ppid:%d\n", getpid(), getppid());
    exit(1);
  }
  pid_t ret = waitpid(id, NULL, 0);
  if(ret > 0) printf("wait success, father pid: %d, ret id: %d\n", getpid(), ret);

    return 0;
}
